//Large Ammo Cache script //modified by Spam_One, appears in city, with hordes !


private ["_rad","_cnps","_flatAreas","_flatCount","_flatNum","_flatArea","_marker","_checking","_people","_area"];

sleep 300;
diag_log " Missions 8 launched";
[player,nil,rSIDECHAT,"A gear cache will be dropped in a town. Find it before others, and bring it to your base !"] call RE;
[nil,nil,rHINT,"A gear cache will be dropped in a town. Find it before others !"] call RE;
private ["_rad","_cnps","_flatAreas","_flatCount","_flatNum","_flatArea","_marker"];

_rad=20000;
_cnps = getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition");
_flatAreas = nearestLocations [_cnps, ["FlatAreaCity","FlatAreaCitySmall"], _rad];
_flatCount = count _flatAreas;
_flatNum = floor (random _flatCount);
_flatArea = _flatAreas select _flatNum;
_area = getpos _flatArea;

_marker = "";
if (CVG_sideMarkers == 0) then {
	_marker_name = STR_MISSION_MARKER_1  + str (serverTime);
	_marker = createMarker [_marker_name,_area];
	_marker setMarkerType "mil_destroy";
	_marker setMarkerColor "ColorRed";
	_marker setMarkerText STR_MISSION_MARKER_1;
	_marker setMarkerSize [1,1];
};

if (CVG_sideMarkers == 1) then {
	_area = [(_area select 0) + random 40, (_area select 1) + random 40,0];
	_marker_name = STR_MISSION_MARKER_1 + str (random 50);
	_marker = createMarker [_marker_name,_area];
	_marker setMarkerType "mil_pickup";
	_marker setMarkerColor "ColorRed";
	_marker setMarkerText STR_MISSION_MARKER_1;
	_marker setMarkerSize [1,1];
};

missionActive = true;
missionVars = [STR_MISSION_MARKER_1,_area];
publicVariable "missionActive";
publicVariable "missionVars";

BOX = createVehicle ["USVehicleBox",[(getpos _flatarea select 0) + (floor random 40), (getpos _flatarea select 1) + (floor random 40),0],[], 0, "NONE"];
BOX setVehicleVarName "USVehicleBox";

[BOX] execVM "craigs_scripts\fillBoxes.sqf";

_checking = 1;
while {_checking == 1} do {
	_people =  nearestObjects [[getpos BOX select 0, getpos BOX select 1,0],["Man"],30];
	if ({isPlayer _x} count _people > 0) then {_checking = 0};
	sleep 1;
};

[player,nil,rSIDECHAT,"The gear cache has been found, nice work !"] call RE;
[nil,nil,rHINT,"You found the ammo crates, but remember you are in a town, Zombies are everywhere !"] call RE;

missionActive = false;
publicVariable "missionActive";
deleteMarker _marker;

// hordes // Spam_One -------------------------------------------------------------------------
// putting a unit which we can rotate for finding a safe pos and randomize where hordes come from
// first Horde --------------------------------------------------------------------------------
_position = [BOX, 50, 50 , 75] call WF_FNCT_getRandomSafePos;

trigger = createTrigger ["EmptyDetector", _position];
trigger setTriggerArea [10,10,0,false];

[trigger,30,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
hint "first horde spawned";
sleep 20;

// second Horde -------------------------------------------------------------------------------
_position = [BOX, 50, 50 , 75] call WF_FNCT_getRandomSafePos;

trigger2 = createTrigger ["EmptyDetector", _position];
trigger2 setTriggerArea [10,10,0,false];

[trigger2,18,CLY_hordetrigger,"normal"] execVM "zombie_scripts\cly_z_horde.sqf"; // horde exec
hint "second horde spawned";
sleep 20;

// End of hordes ------------------------------------------------------------------------------

deleteVehicle _safePos;

SM1=8;
[0] execVM "sideMissions\SMfinder.sqf";